package com.tyk.bookstore.back.platform.model.vo;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author tyk
 * @description 行政区域
 */
@Data
@Schema(name = "AreaListVo", description = "行政区域")
public class AreaVo implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    @Schema(description = "行政区划代码")
    private Long code;

    @Schema(description = "父级行政区划代码")
    private Long parentCode;

    @Schema(description = "名称")
    private String name;

    @Schema(description = "下级行政区")
    private List<AreaVo> children;

    public AreaVo(Long code, String name) {
        this.code = code;
        this.name = name;
    }

    /**
     * 条件子结点
     */
    public void addChild(AreaVo vo) {
        if (this.children == null) this.children = new ArrayList<>();
        this.children.add(vo);
    }

}
